package tree.迭代bfs;

import po.TreeNode;

import java.util.Deque;
import java.util.LinkedList;

/**
 * @author songZiHao
 * @version 1.0.0
 * @ClassName 二叉树的完全性检验958.java
 * @Description https://leetcode-cn.com/problems/check-completeness-of-a-binary-tree/
 * @createTime 2021年08月09日 19:15:00
 */
public class 二叉树的完全性检验958 {
	public boolean isCompleteTree(TreeNode root) {
		Deque<TreeNode> deque = new LinkedList<>();
		deque.offer(root);
		boolean end = false;
		while (!deque.isEmpty()) {
			TreeNode node = deque.poll();
			if (end && node != null) {
				return false;
			}
			if (node == null) {
				end = true;
				continue;
			}
			deque.offer(node.left);
			deque.offer(node.right);
		}
		return true;
	}
}
